package com.tuozixuan;

import java.util.concurrent.TimeUnit;

import cn.hutool.core.date.DateUtil;
import cn.hutool.core.date.TimeInterval;
import cn.hutool.core.lang.Console;
import cn.hutool.core.thread.ThreadUtil;

public class TimeIntervalDemo {

	public static void main(String[] args) throws InterruptedException {
		
		TimeInterval timer = DateUtil.timer();
		TimeUnit.SECONDS.sleep(1);
		System.out.println("time:" + timer.interval() + "ms");

		
		TimeInterval timer1 = DateUtil.timer();
		TimeUnit.SECONDS.sleep(1);
		System.out.println("time:" + timer1.intervalRestart() + "ms");
		
		TimeUnit.SECONDS.sleep(2);
		System.out.println("time:" + timer1.intervalRestart() + "ms");
		
		
		final TimeInterval timer3 = new TimeInterval();
		// 分组1
		timer3.start("1");
		ThreadUtil.sleep(800);

		// 分组2
		timer3.start("2");
		ThreadUtil.sleep(900);

		Console.log("Timer 1 took {} ms", timer3.intervalMs("1"));
		Console.log("Timer 2 took {} ms", timer3.intervalMs("2"));

	}

}
